#pragma once
namespace SimpleLogger
{
	class CLogWriter
	{
	protected:
		CLogWriter(void);
		~CLogWriter(void);
	public:
		static CLogWriter*	GetLogWriterInstance();
		void			Release();

		BOOL			OpenLogAppender(LogAppender logAppender, wchar_t *pszPara);
		BOOL			CloseLogAppender();
		BOOL			ResetWritter(LogAppender logAppender, DWORD dwBufSize, LPVOID pData);

		BOOL			WriteLog(const wchar_t *pszLogContents, bool bForceOutput = false);
		BOOL			WriteLog(const char *pszLogContents, bool bForceOutput = false);
		BOOL			WriteLog(const BYTE *pLogContents, DWORD dwSize, bool bForceOutput = false);

		BOOL			ChangeBufSize(DWORD dwSize);
		BOOL			Flush();

	protected:
		BOOL			AppendToBuf(const BYTE *pContents, DWORD dwSize);
	private:
		static CRITICAL_SECTION	s_sectionWriteLog;
		static CRITICAL_SECTION	s_sectionBuffer;
		static CLogWriter*		m_pLogWriter;

		BYTE*			m_pCotentsBuf;
		DWORD			m_dwCurrentSize;
		DWORD			m_dwBufSize;//Bytes, default value 1024*1024

		LogAppender		m_logAppender;
		wchar_t*		m_pszAppenderPara;
		HANDLE			m_hAppender;

		BOOL			m_bNeedFreeConsole;
	};

}
